#include <iostream>
using namespace std;

template <class T>
class Autorelease{
    public:
    Autorelease(T* p)
    :_p(p)
    {

    }
    ~Autorelease(){
        cout<<"~Autorelease"<<endl;
        if(_p){
            delete _p;
            _p=nullptr;
        }
    }
    private:
        T* _p;
};

class Test{
public:
    Test(){
        cout<<"test"<<endl;
    }
    ~Test(){
        cout<<"~test"<<endl;
    }
    int num=10;
};
void test(){
    Autorelease<Test> ar(new Test());
}
int main(int argc, char * argv[]){
    test();
    return 0;
}

